package com.hsc.www.docker;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;

@EnableWebSocket
@Configuration
public class MyWebSocketConfig implements WebSocketConfigurer {

    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(handler(), "/webSocket/socketServer")
                .addInterceptors(handlerInterceptor())
                .setAllowedOrigins("*");


        registry.addHandler(handler(), "/sockJs/socketServer")
                .setAllowedOrigins("http://localhost:28180")
                .addInterceptors(handlerInterceptor())
                .withSockJS();
    }


    private org.springframework.web.socket.WebSocketHandler handler() {
        return new MyWebSocketHandler();
    }

    private HandshakeInterceptor handlerInterceptor() {
        return new MyWebSocketHandlerInterceptor();
    }
}
